<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Deferred</title>
	<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
</head>
<body>

<script>
	$(function(){
		function loadImg(src){
			var dtd = $.Deferred();  // 定义延迟对象
			var img = new Image();
			img.onload = function(){
				dtd.resolve(img)
			}
			img.onerror = function(){
				dtd.reject()
			}
			img.src = src;
			return dtd;  // 记得要返回哦
		}
		var result = loadImg('https://www.epubit.com/oldres/writeBookImg/979B4F1C-CAC6-4E50-BED4-EC79C050FDC3');
		result.then(function(img){
			console.log(img.width)
		},function(){
			console.log('fail')
		})
	});
</script>
</body>
</html>